#include "pch.h"
#include "WinRegistry.h"
#include "Poco/Util/WinRegistryKey.h"
#include "Poco/Exception.h"
#include "ResultError.h"
#include "ComTools.h"

namespace Poco {
	namespace Util {
		class WinRegistryKey;
	}
}

namespace yzq {
	WinRegistry::WinRegistry(const std::string& key, bool readOnly) :
		m_winRegistry(new Poco::Util::WinRegistryKey(key, readOnly)) {
	}

	WinRegistry::~WinRegistry() {
	}

	std::string WinRegistry::setString(const std::string & name, const std::string & value) {
		try {
			m_winRegistry->setString(name, value);
		}
		catch (const Poco::Exception & exc) {
			AddErrorMsg(exc.code(), s2ws(exc.displayText()).c_str());
			SetLastError(exc.code());
			return "error";
		}
		return std::string();
	}

	std::string WinRegistry::getString(const std::string & name) {
		try {
			return m_winRegistry->getString(name);
		}
		catch (const Poco::Exception & exc) {
			AddErrorMsg(exc.code(), s2ws(exc.displayText()).c_str());
			SetLastError(exc.code());
			//MessageBoxA(NULL, exc.displayText().c_str(), NULL, NULL);
			return "error";
		}
	}

	void WinRegistry::setInt(const std::string & name, int value) {
		try {
			m_winRegistry->setInt(name, value);
		}
		catch (const Poco::Exception & exc) {
			AddErrorMsg(exc.code(), s2ws(exc.displayText()).c_str());
			SetLastError(exc.code());
		}
	}
}
